<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        table {
            border: 1px solid gray;
            width: 600px;
            margin: 100px auto;
        }

        th,td {
            border: 1px solid #000; 
            text-align: center;
        }
    </style>
</head>

<body>
    <div id="app">
        <table>
            <caption>欢迎光临_vue开发的收银系统_水果店</caption>
            <tr>
                <th>苹果10 ￥ / 斤，折扣< 8折>
                </th>
            </tr>
            <tr>
                <td>
                    请输入你要购买的斤数 <input v-model="count" type="number">
                </td>
            </tr>
            <tr>
                <td><button @click="checkout">结账买单~</button></td>
            </tr>
            <tr>
                <!-- 花括号是写到html中，它是插值语法 -->
                <!-- 作用：渲染数据 -->
                <td>结账单：总价：{{ total }} ￥元 折后价：{{ total * .8 }}￥元 省了：{{ total * .2 }} ￥元</td>
            </tr>
        </table>
    </div>

    <script src="./vue.js"></script>
    <script>
        new Vue({
            el: '#app',
            data() {
                return {
                    count: 0,
                    // 总价
                    total: 0
                }
            },
            methods: {
                checkout () {
                    if (this.count < 0) {
                        alert('斤数不能小于0')
                        this.count = 0
                        this.total = 0
                        return
                    }
                    // 用用户输入的数量 * 10 得到总价
                    this.total = this.count * 10
                }
            }
        })
    </script>
</body>

</html>